package com.example.commonlib.commonutil;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by aiyou on 2017/4/6.
 */

public class JugementInputUtil {


    public static final String USERNAME_PATTERN = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$";
    public static final String NICKNAME_PATTERN = "^[a-zA-Z0-9_\u4E00-\u9FA5]{2,15}$";
    public static final String PASSWORD_PATTERN = "^[a-zA-Z0-9][a-zA-Z0-9+-\\\\*/=\\[\\]:.!@#$%\\^&_]{5,15}$";
    public static final String PHONE_PATTERN = "(13[0-9]|15[0-9]|18[0-9]|17[0-9])\\d{8}";
    public static final String SMSCODE_PATTERN = "smaCode";
    public static final String PICCODE_PATTERN = "picCode";

    private static final int SMS_CODE_LENTH = 4;
    private static final int PIC_CODE_LENTH = 4;


    public static boolean jugmentInput(String matcherStr, String pattern){

        if (TextUtils.isEmpty(matcherStr))
            return false;

        if(pattern.equals(SMSCODE_PATTERN)){
            if (matcherStr.length() == SMS_CODE_LENTH)
                return true;
            else
                return false;
        }

        if(pattern.equals(PICCODE_PATTERN)){
            if (matcherStr.length() == PIC_CODE_LENTH)
                return true;
            else
                return false;
        }

        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(matcherStr);
        return m.matches();
    }


}
